var oIFrame = null;
var xmlHttp = null;
        
        function createIFrame() {
            var oIFrameElement = document.createElement("iframe");
            oIFrameElement.style.display = "none";
            oIFrameElement.name = "hiddenFrame";
            oIFrameElement.id = "hiddenFrame";
            document.body.appendChild(oIFrameElement);
            
            oIFrame = frames["hiddenFrame"];
        }
        
        function checkIFrame() {
            if (!oIFrame) {
                createIFrame();                
            } 
        
            //takes a cycle for some browers to recognize the new element
            setTimeout(function () {
                oIFrame.location = "ProxyForm.html";
            }, 10);                              
        }
        
        function createInputField(oHiddenForm, sName, sValue) {
            oHidden = oIFrame.document.createElement("input");
            oHidden.type = "hidden";
            oHidden.name = sName;        								
            oHidden.value = sValue;
            oHiddenForm.appendChild(oHidden);					
        }
        
        function formReady() {
            var oHiddenForm = oIFrame.document.forms[0];
		createInputField(oHiddenForm, document.getElementById("UserName").name,document.getElementById("UserName").value);
		createInputField(oHiddenForm, document.getElementById("PassWord").name,document.getElementById("PassWord").value);
		createInputField(oHiddenForm, document.getElementById("RealName").name,document.getElementById("RealName").value);
		createInputField(oHiddenForm, document.getElementById("Question").name,document.getElementById("Question").value);
                createInputField(oHiddenForm, document.getElementById("EmailAddress").name,document.getElementById("EmailAddress").value);
		createInputField(oHiddenForm, document.getElementById("Answer").name,document.getElementById("Answer").value);
		createInputField(oHiddenForm, document.getElementById("WordVerification").name,document.getElementById("WordVerification").value.toLowerCase());
                 
                oHiddenForm.action = document.forms[0].action;
                oHiddenForm.submit();
        };// JavaScript Document
		
        function saveResult(sMessage) {
            if(sMessage=="verificationFail"){
		document.getElementById("WordVerificationPic").src="wrong.gif";
		document.getElementById("WordVerificationPic").alt="VerifyError!";
		document.getElementById("WordVerificationPic").style.display="block";
		document.getElementById("verificationPicture").src="loading.jpg";
		document.getElementById("verificationPicture").src="verifyWord.php";
		document.getElementById("WordVerification").focus;
            }else{
		var createStatus = document.getElementById("createStatus");
            	createStatus.innerHTML = "Request completed: " + sMessage;
            }
        }
		
	function verifyAddress() {  
            var email = document.getElementById("Email").value;
            var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;  
            flag = pattern.test(email);
            if(flag){  
                document.getElementById("EmailAddressPic").src="right.gif";
                document.getElementById("EmailAddressPic").alt="The address is ok!";
            }  
            else{  
                document.getElementById("EmailAddressPic").src="wrong.gif";
				document.getElementById("EmailAddressPic").alt="The address is wrong!";
            }
			document.getElementById("EmailAddressPic").style.display="block";
        }
		
	function checkUserName(){
            var userName=document.getElementById("UserName").value;
            //document.getElementById("createStatus").innerHTML=userName;
            if (!xmlHttp) {
                document.getElementById("createStatus").innerHTML=userName;
                if (window.ActiveXObject) {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} else if (window.XMLHttpRequest) {
                    xmlHttp = new XMLHttpRequest();
		}
            } else if (oXHR.readyState != 0) {
                document.getElementById("createStatus").innerHTML=userName;
		xmlHttp.abort();
            }
            
            xmlHttp.open("get", "checkID?id="+userName, true);
            xmlHttp.onreadystatechange = function () { 
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                        var aData = xmlHttp.responseText;
                           // document.getElementById("createStatus").innerHTML=aData;
                            if(aData=="true"){
                                document.getElementById("UserNamePic").src="right.gif";
				document.getElementById("UserNamePic").alt="OK! The username is available!";
				document.getElementById("UserNamePic").style.display="block";
                            }else{
				document.getElementById("UserNamePic").src="wrong.gif";
				document.getElementById("UserNamePic").alt="Sorry, the username is occupied!";
				document.getElementById("UserNamePic").style.display="block";
                            }
                        xmlHttp=null;
                    }                         
                }
            };    	
            xmlHttp.send(null);
	}

	function checkPassWord(){
            var passWord=document.getElementById("PassWord").value;
            var length=passWord.length;
            if(length<=5){
		document.getElementById("PassWordPic").src="short.jpg";
		document.getElementById("PassWordPic").alt="Short!";
            }else if(length<=10){
		document.getElementById("PassWordPic").src="middle.jpg";
		document.getElementById("PassWordPic").alt="Middle!";
            }else{
		document.getElementById("PassWordPic").src="long.jpg";
		document.getElementById("PassWordPic").alt="Long!";
            }
            document.getElementById("PassWordPic").style.display="block";
	}
		
	function verifyPassWord(){
            var passWord1=document.getElementById("PassWord").value;
            var passWord2=document.getElementById("PassWordConform").value;
            if(passWord1 ==passWord2){
		document.getElementById("PassWordConformPic").src="right.gif";
		document.getElementById("PassWordConformPic").alt="The two passwords are no the same!";
            }else{  
                document.getElementById("PassWordConformPic").src="wrong.gif";
		document.getElementById("PassWordConformPic").alt="The verify is sucessed!";
            }
            document.getElementById("PassWordConformPic").style.display="block";
	}